-
Notifications
You must be signed in to change notification settings - Fork 217
Add demo on loading classical data with low-depth circuits #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…nist/requirements.in and update the reference types in demonstrations_v2/low_depth_circuits_mnist/metadata.json
Your preview is ready 🎉!You can view your changes here
|
DSGuala
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made an initial skim and left comments. Overall a very nice/complete first draft.
Still pending from my side:
- In depth review of the text for clarity
- In depth review of the code for efficiency and output
But basically I think 1 or two more rounds of review and this should be ready to go.
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
Co-authored-by: Diego <[email protected]>
…details one the three steps
Co-authored-by: Daniela Angulo <[email protected]>
Co-authored-by: Daniela Angulo <[email protected]>
Co-authored-by: Diego <[email protected]>
…humbnails Add images and update metadata
Co-authored-by: Daniela Angulo <[email protected]>
Co-authored-by: Daniela Angulo <[email protected]>
DSGuala
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, left some final comments/suggestions, but ready to go from my side once they're addressed.
| n = 2 * int(np.log2(N)) | ||
| # reorder pixels hierarchically | ||
| states = np.reshape(images, (batchsize, *(2,) * n)) | ||
| states = np.transpose(states, [0] + [ax + 1 for q in range(n // 2) for ax in (q, q + n // 2)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import jax | ||
| import pennylane as qml | ||
|
|
||
| # JAX supports the single-precision numbers by default. The following line enables double-precision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remove the horizontal scroll bar.
| # JAX supports the single-precision numbers by default. The following line enables double-precision. | |
| # JAX supports the single-precision numbers by default. | |
| # The following line enables double-precision. |
| :param circuit_layout: List of tuples containing gate types ('RY' or 'CNOT') and their target wires. | ||
| :return circuit: A JAX-compiled quantum circuit function that takes parameters and returns the quantum state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remove the horizontal scroll bar
| :param circuit_layout: List of tuples containing gate types ('RY' or 'CNOT') and their target wires. | |
| :return circuit: A JAX-compiled quantum circuit function that takes parameters and returns the quantum state. | |
| :param circuit_layout: List of tuples containing gate types ('RY' or 'CNOT') | |
| and their target wires. | |
| :return circuit: A JAX-compiled quantum circuit function that takes parameters and | |
| returns the quantum state. |
| rec_0 = FRQI_decoding(states_01[labels_01 == 0][idx_0][None, :])[0] | ||
| rec_1 = FRQI_decoding(states_01[labels_01 == 1][idx_1][None, :])[0] | ||
|
|
||
| # Create a grid of figures to show both the fidelity distribution and the original and reconstructed images |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remove the horizontal scroll bar
| # Create a grid of figures to show both the fidelity distribution and the original and reconstructed images | |
| # Create a grid of figures to show both the fidelity distribution and the original | |
| # and reconstructed images |
| ) # we select the real part only, as the the imaginary part is zero since we only use RY and CNOT gates | ||
| y_all = jnp.asarray(labels_01, dtype=jnp.int32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remove the horizontal scroll bar.
| ) # we select the real part only, as the the imaginary part is zero since we only use RY and CNOT gates | |
| y_all = jnp.asarray(labels_01, dtype=jnp.int32) | |
| ) # we select the real part only | |
| # the imaginary part is zero since we only use RY and CNOT gates | |
| y_all = jnp.asarray(labels_01, dtype=jnp.int32) |
| (loss, acc), grads = jax.value_and_grad(lambda p: loss_acc(p, batch_x, batch_y), has_aux=True)( | ||
| params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remove the horizontal scroll bar
| (loss, acc), grads = jax.value_and_grad(lambda p: loss_acc(p, batch_x, batch_y), has_aux=True)( | |
| params | |
| func = lambda p: loss_acc(p, batch_x, batch_y) | |
| (loss, acc), grads = jax.value_and_grad(func, has_aux=True)( | |
| params |
| quantum circuits to load classical image data into quantum states. | ||
|
|
||
| This demo gives an introduction to the paper **“Typical Machine Learning Datasets as | ||
| Low‑Depth Quantum Circuits”** (2025). We will discuss the following three steps: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something about "discuss steps" with "define, construct, train and evaluate" sounds a bit strange to me.
| Low‑Depth Quantum Circuits”** (2025). We will discuss the following three steps: | |
| Low‑Depth Quantum Circuits”** (2025). We will do the following: |

Title:
Add demo on loading classical data with low-depth circuits
Summary:
This pull request adds a new demonstration on how to efficiently load classical image data into quantum states using low-depth quantum circuits, based on the paper "Typical Machine Learning Datasets as Low‑Depth Quantum Circuits". The demo uses the MNIST dataset and shows how to train a variational quantum classifier on the encoded data. This demo leverages the new qml.data module for dataset loading.
Relevant references:
Possible Drawbacks:
The dataset required for this demo is large (~1GB), which might be a consideration for users with limited bandwidth or storage.
Related GitHub Issues:
None
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
Promote the new
qml.datafeature for loading datasets and show a PennyLane implementation of a recent paper on efficient data loading for QML.QML researchers, students, and practitioners interested in efficient data loading techniques and their application to image classification tasks.
Quantum Machine Learning, Quantum Datasets, Image Loading, Low-depth circuits, Variational Quantum Classifier, MNIST, PennyLane, qml.data
(more details here)